import { config } from './config';
import setErrCommonProperties from './setErrCommonProperties';

const request = (uri, data) => {
  const { server } = config;
  return fetch(`${server}${uri}`, {
    method: 'POST',
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify(data),
  })
    .catch((err) => console.log(err));
};

// 错误上报
const reportError = (errInfo) => {
  request('/error', setErrCommonProperties(errInfo));
};

// 性能上报
const reportPerformance = (performance) => {
  request('/performance', performance);
};

export { reportError, reportPerformance };
